
angular.module('payhistory.controller', ['payhistory.service'])
    .controller("payhistoryCtrl", function ($scope,$rootScope,$http,ionicDatePicker) {


        //payhistoryFty.gethttp(a,b,c)需要三个参数 a：借口 b：sessionid c:参数
        var port='/fk/fk.json';
        var CCSessionId =localStorage.getItem("CCSessionId"),
            para=null,
            ends=null,starts=null,
            para1='flag=0&pageIndex=4&pageSize=6&startDate=2015-12-12&endDate=2016-12-12';
        $scope.checkhistory=function(date1){

            console.log(date1);
            if(date1!=undefined){
                console.log(123);
                para=para1;
            }else{
                if( $scope.starttime==undefined||$scope.endtimer==undefined){
                    alert ("请输入开始时间和结束时间")
                    return
                }
               starts= $scope.starttime.split('/').join('-');
               ends= $scope.endtimer.split('/').join('-');
                para='flag=0&pageIndex=4&pageSize=6&startDate='+starts+'&endDate='+ends
            }
            console.log(para);

            var url0=$rootScope.myglobal.serverurl+port+ '?CCSessionId='+CCSessionId;

            $http.get( url0+'&'+para).success(function(data){
                console.log(data.resultList);
                $scope.arrlist=data.resultList
            })
        }
        //初入页面的历史记录
        $scope.checkhistory(para1)



    //    判断状态
        $scope.states=function(a){
          var val=null
            switch (a){
                case 0:
                    val= '发起'
                    break;
                case 1:
                    val= '内部审批中'
                    break;
                case 2:
                    val= '待银行预处理'
                    break;
                case 3:
                    val= '送达银行失败'
                    break;
                case 4:
                    val= '送达银行主机失败'
                    break;
                case 5:
                    val= '待银行主机处理'
                    break;
                case 6:
                    val= '本地处理失败'
                    break;
                case 7:
                    val= '完成'
                    break;
                case 8:
                    val= '执行中'
                    break;

            }
            return val

        }
        //配置时间日历
        var start = {
            callback: function (val) {  //Mandatory
                console.log('Return value from the datepicker popup is : ' + val, new Date(val));
                $scope.starttime = new Date(val).toLocaleDateString();
            },
            disabledDates: [            //Optional
            ],
            from: new Date(2000, 1, 1), //Optional
            to: new Date(2128, 10, 30), //Optional
            inputDate: new Date(),      //Optional
            mondayFirst: true,          //Optional
            disableWeekdays: [""],       //Optional
            closeOnSelect: false,       //Optional
            templateType: 'popup'       //Optional
        };
        $scope.start = function () {
            ionicDatePicker.openDatePicker(start);
        };
        var end = {
            callback: function (val) {  //Mandatory
                $scope.endtimer = new Date(val).toLocaleDateString();
            },
            disabledDates: [            //Optional
            ],
            from: new Date(2000, 1, 1), //Optional
            to: new Date(2128, 10, 30), //Optional
            inputDate: new Date(),      //Optional
            mondayFirst: true,          //Optional
            disableWeekdays: [""],       //Optional
            closeOnSelect: false,       //Optional
            templateType: 'popup'       //Optional
        }
        $scope.end = function () {
            ionicDatePicker.openDatePicker(end);
        };




    })



